<template>
  <div>
    <form>
      用户名:<input name="username" type="text"><br>
      密码:<input name="password" type="password"><br>
    </form>
  </div>
</template>

<script>
  import {to_url,storage} from '../util/util'
  import {authToken} from '../api/api'; // 引入我们 封装好的两个接口函数。

  export default {
    name: "Login",
    beforeCreate: function () {
      if (this.$route.query.token != null){
        authToken(this.$route.query.token).then(user=>{
          storage.set('user',user);
           user =  storage.get('user');
          console.log('user',user);
          if(this.$route.query.fromUrl == null){
            this.$router.push('/')
          }
          this.$router.push(this.$route.query.fromUrl)
        })

      }else{
        let urlstr = to_url("http://localhost:8080/#/login", {authUrl: "http://localhost:8080/#/login",fromUrl:this.$route.query.fromUrl})
        location.href = urlstr;
      }

    }


  }
</script>

<style scoped>

</style>
